
// 封装请求数据接口代码
// 设置请求的条数
let times = 0;
const app = getApp();

export const request = (params) => {
  console.info(JSON.stringify(params))
  //判断url中是否带有/my/ 带上header tooken
  // let header = {...params.header};
  // if(params.url.includes("/my/")){
  //   //拼接header 带上Tooken
  //   header["Autorization"]=wx.getStorageSync("token");
  // }
  // 定义公共接口前缀
  var baseUrl = app.globalData.baseUrl;
  // 每请求一次加一次
  times++;
  // 发送请求前设置加载中文字
  wx.showLoading({
    title: '加载中',
  })

  return new Promise((resolve, resject) => {
    wx.request({
      data: params,
      // 重新定义url路径
      url: baseUrl + params.url,
      header: {
        'content-type': 'application/json',
        'Authorization': app.globalData.key
      },
      method: "POST",
      success: (result) => {
        resolve(result)
        if(result.data.code===1001001){
        }
      },
      fail: (err) => {
        resject(err)
      },
      complete: () => {
        times--;
        if (times === 0) {
          wx.hideLoading()
        }
      }
    });

  })
}